package com.huaxin.device.models;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.huaxin.device.dto.enums.AlarmLevel;
import com.huaxin.device.dto.enums.AlarmType;
import com.huaxin.hxenum.enums.DeviceType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 设备报警信息
 */
@Data
@TableName("device_alarms")
public class DeviceAlarm {

    /**
     * 唯一ID（UUID）- 主键
     */
    @TableId(value = "id", type = IdType.ASSIGN_UUID)
    private String id;
    /**
     * 组织ID
     */
    @TableField(value = "org_id")
    private String orgId;
    /**
     * 自增序列号（唯一索引，非主键）
     */
    @TableField(value = "auto_id")
    private Long autoId;

    /**
     * 设备ID
     */
    @TableField(value = "device_id")
    @Schema(description = "设备ID", example = "d123e456-789a-bcde-f012-3456789abcde")
    private String deviceId;

    /**
     * 设备类型
     */
    @TableField(value = "device_type")
    @Schema(description = "设备类型", example = "circuit_breaker")
    private DeviceType deviceType;

    /**
     * 报警类型
     */
    @TableField(value = "alarm_type")
    @Schema(description = "报警类型", example = "over_current")
    private AlarmType alarmType;

    /**
     * 报警等级
     */
    @TableField(value = "alarm_level")
    @Schema(description = "报警等级", example = "3")
    private AlarmLevel alarmLevel;

    /**
     * 报警信息（参数已替换的实际消息）
     */
    @TableField(value = "alarm_message")
    @Schema(description = "报警信息（已填充参数）", example = "设备 CB-001 发生严重报警，电流达到 15.6A")
    private String alarmMessage;

    /**
     * 触发时的实际值
     */
    @TableField(value = "trigger_value")
    @Schema(description = "触发时的实际值", example = "15.6A")
    private String triggerValue;

    /**
     * 触发阈值
     */
    @TableField(value = "threshold_value")
    @Schema(description = "触发阈值", example = "12.0A")
    private String thresholdValue;

    /**
     * 对应的阈值规则ID
     */
    @TableField(value = "rule_id")
    @Schema(description = "阈值规则ID", example = "r123e456-789a-bcde-f012-3456789abcde")
    private String ruleId;

    /**
     * 持续时间（秒）
     */
    @TableField(value = "duration_sec")
    @Schema(description = "持续时间（秒）", example = "30")
    private Integer durationSec;

    /**
     * 组织家族ID
     */
    @TableField(value = "family_id")
    @Schema(description = "组织家族ID", example = "f3b2f8e1-4c5d-4e6f-8b2a-1c2d3e4f5a6b")
    private String familyId;

    /**
     * 创建时间
     */
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createdAt;

    /**
     * 是否已解决
     * 0: 未解决 1: 已解决
     * 默认为未解决
     */
    @TableField(value = "is_resolved")
    @Schema(description = "是否已解决", example = "0")
    private Boolean isResolved = false;

    /**
     * 解决时间
     */
    @TableField(value = "resolved_at")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(description = "解决时间", example = "2025-08-17 14:00:00")
    private LocalDateTime resolvedAt;

    /**
     * 解决人
     */
    @TableField(value = "resolved_by")
    @Schema(description = "解决人ID", example = "u123e456-789a-bcde-f012-3456789abcde")
    private String resolvedBy;

    /**
     * 是否删除（0:未删, 1:已删）
     */
    @TableLogic
    @TableField(value = "is_deleted")
    private Integer isDeleted = 0;

    /**
     * 删除时间
     */
    @TableField(value = "deleted_at", fill = FieldFill.UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime deletedAt;

    /**
     * 删除人
     */
    @TableField(value = "deleted_by", fill = FieldFill.UPDATE)
    private String deletedBy;
}